package org.yds.quality.utils;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FunctionUtils {

    public static Set<String> getEventParams(List<String> classNameList) {
        Set<String> result = new HashSet<>();
        classNameList.forEach(className -> {
            result.addAll(getParm(className));
        });
        return result;
    }


    private static List<String> getParm(String className) {
        try {
            // 加载类
            Class<?> clazz = Class.forName("org.yds.quality.function.dft." + className);
            // 创建对象
            Object instance = clazz.getDeclaredConstructor().newInstance();
            // 获取方法
            Method method = clazz.getMethod("getEventParams");
            // 调用方法并返回结果
            Object invoke = method.invoke(instance);
            return (List<String>) invoke;
        } catch (Exception e) {
            throw new RuntimeException("Failed to get event params for class: " + className, e);
        }

    }
}
